package com.tan.kotlintest.adapter

import android.support.v7.widget.RecyclerView
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.tan.kotlintest.R
import com.tan.kotlintest.base.BaseActivity
import com.tan.kotlintest.bean.ActorEarnDetailListBean
import java.util.*


class ActorEarnDetailRecyclerAdapter(private val mContext: BaseActivity) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    private var mBeans: List<ActorEarnDetailListBean>? = ArrayList()

    fun loadData(beans: List<ActorEarnDetailListBean>) {
        mBeans = beans
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val itemView = LayoutInflater.from(mContext).inflate(R.layout.item_actor_earn_detail_recycler_layout, parent, false)
        return MyViewHolder(itemView)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val bean = mBeans!![position]
        val mHolder = holder as MyViewHolder
        //金币
        val gold = bean.totalGold.toString() + mContext.resources.getString(R.string.gold)
        mHolder.mGoldTv.text = gold
        //时间
        val time = bean.t_change_time
        if (!TextUtils.isEmpty(time)) {
            mHolder.mTimeTv.text = time
        }
    }

    override fun getItemCount(): Int {
        return mBeans?.size ?: 0
    }

    internal inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var mGoldTv: TextView = itemView.findViewById(R.id.gold_tv)
        var mTimeTv: TextView = itemView.findViewById(R.id.time_tv)

    }

}
